<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>客户端上传文件到七牛云</title>
</head>
<body>
<input id="fileLoader" placeholder="上传文件" type="file">
<button onclick="handleClick()">上传文件</button>
<script src="qiniu.min.js"></script>
<script>
    const loader = document.querySelector("#fileLoader")
    const handleClick = () => {
        const file = loader.files[0]
        const observer = {
            next(res){
                console.log('next',res)
            },
            error(err){
                console.log('error',err)
            },
            complete(res){
                console.log('complete',res)
            }
        }
        const config = {
            useCdnDomain: true,
            region: qiniu.region.z2
        };
        const putExtra = {

        };

        const token = "MV2HLhIlIjfeIQfu1qKYpcKxlhg3aZ3a3kBWnd2g:oqECC7Lgp1X8e1ekg9N6II79kyA=:eyJkZWFkbGluZSI6MTczNTI5ODEyNSwic2NvcGUiOiJ6ZW5nd2VpamllIn0="
        const observable = qiniu.upload(file, "blogx/client/xx.png", token, putExtra, config)
        const subscription = observable.subscribe(observer) // 上传开始
        console.log(subscription)
    }
</script>
</body>
</html>